clear
set more off, perm
cd /Users/zachbrown/Projects/PriceTransparency/Data/



////////////////////
// MED Claims
////////////////////

guse member_key icd* using Raw/med_clm/med_clm_2005_clean.dta, clear
forval yr = 2006(1)2014 {
	disp "year: `yr'"
	tempfile tmpdata
	shell nice gunzip "Raw/med_clm/med_clm_`yr'_clean.dta" -c > `tmpdata'
	append using `tmpdata', keep(member_key icd*)
}

rename icd_diag_01_prim DX1
rename icd_diag_02 DX2
rename icd_diag_03 DX3
rename icd_diag_04 DX4
rename icd_diag_05 DX5
rename icd_diag_06 DX6
rename icd_diag_07 DX7
rename icd_diag_08 DX8
rename icd_diag_09 DX9
rename icd_diag_10 DX10
rename icd_diag_11 DX11
rename icd_diag_12 DX12
rename icd_diag_13 DX13


// Make Charlson score for each patient
charlson DX1-DX13, icd(9) idvar(member_key) assign0 wtchrl  cmorb

compress
save build/charlson_by_member_key.dta, replace

sort member_key
merge m:1 member_key using Raw/members/member_100k_sample.dta, keep(match) nogen sorted
distinct member_key
compress
save build/charlson_by_member_key_sample.dta, replace


